Page({
  /**
   * 页面的初始数据
   */
  data: {
    originList: [],
    tabList: ["待受理", "已受理"],
    selectValue: '待受理',
    loading: true,
    pageNum: 1,
    pageSize: 10,
    serach_pro: ''
  },
  selectTab(e) {
    console.log(e);
    this.setData({
      selectValue: e.detail.title,
      originList: [],
      pageNum: 1,
    });
    if (this.isSecondFilterfunction()) {
      this.getInfos2()
    } else {
      this.getInfos()
    }
  },
  goScreening() {
    this.setData({
      isUpdate: false
    })
    const content = JSON.stringify(this.data.selectedObj)
    wx.navigateTo({
      url: `/sub_jinfu/screening/screening?content=${content}`,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(this.isSecondFilterfunction());
    if (this.isSecondFilterfunction()) {
      this.getInfos2()
    } else {
      this.getInfos()
    }

  },

  // 银行用户分页查询
  async getInfos() {
    this.setData({
      loading: true
    })
    wx.showLoading({
      title: "加载中",
    });
    // 全量的条件
    // wx.getStorageSync("userInfo").userId
    let params = {}
    if (this.data.selectValue == '待受理') {
      params = {
        userId: "",
        bankId: wx.getStorageSync("userInfo").highLevelBankId,
        corpName: this.data.serach_pro,
        pageNum: this.data.pageNum,
        pageSize: 10
      };
    } else {
      params = {
        userId: wx.getStorageSync("userInfo").userId,
        bankId: "",
        corpName: this.data.serach_pro,
        pageNum:  this.data.pageNum,
        pageSize: 10
      };
    }

    console.log(params, "finalParams");
    const res = await getApp().globalData.request(
      "/sip/findFinancePage",
      params,
      "POST"
    );
    wx.hideLoading();
    console.log(res, "列表信息res");
    this.setData({
      originList: this.data.originList.concat(res.data.list),
      loading: false,
    });
  },

  // 银监用户分页查询
  async getInfos2() {
    this.setData({
      loading: true
    })
    wx.showLoading({
      title: "加载中",
    });
    // 全量的条件

    // wx.getStorageSync("userInfo").userId
    let params = {}
    if (this.data.selectValue == '待受理') {
      params = {
        userId: "",
        bankId: "",
        corpName: this.data.serach_pro,
        pageNum: this.data.pageNum,
        pageSize: 10
      };
    } else {
      params = {
        userId: wx.getStorageSync("userInfo").userId,
        bankId: "",
        corpName: this.data.serach_pro,
        pageNum: this.data.pageNum,
        pageSize: 10
      };
    }

    console.log(params, "finalParams");
    const res = await getApp().globalData.request(
      "/sip/findCbrcFinancePage",
      params,
      "POST"
    );
    wx.hideLoading();
    console.log(res, "列表信息res");
    this.setData({
      originList: this.data.originList.concat(res.data.list),
      loading: false,
    });
  },

  toDetail(e) {
    wx.navigateTo({
      url: `/sub_xuqiu/list1_detail/list1_detail?id=${e.currentTarget.dataset.id}&auditstate=${this.data.selectValue}`,
    })
  },

  // 是否是一级管理
  isAdminFilter() {
    let roleArr = wx.getStorageSync('userInfo').corpRole
    var rusult = roleArr.some(function (item) {
      return item == "fir_admin"
    })
    return rusult
  },
  // 是否是银监
  isSecondFilterfunction() {
    let roleArr = wx.getStorageSync('userInfo').corpRole
    var rusult = roleArr.some(function (item) {
      return item == "cbrc"
    })
    return rusult
  },


  goOnChange(e) {
    // console.log(e, '1323213213')
    this.setData({
      serach_pro: e.detail,
    });
  },

  goSearch() {
    this.setData({
      pageNum: 1,
      originList: [],
    })
    if (this.isSecondFilterfunction()) {
      this.getInfos2()
    } else {
      this.getInfos()
    }
  },

  scrollBottom() {
    this.data.pageNum++
    this.setData({
      pageNum:this.data.pageNum
    })
    console.log( this.data.pageNum)
    if (this.isSecondFilterfunction()) {
      this.getInfos2()
    } else {
      this.getInfos()
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.refresh) {
      this.setData({
        pageNum: 1,
        originList: [],
      })
      if (this.isSecondFilterfunction()) {
        this.getInfos2()
      } else {
        this.getInfos()
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});